package com.ruoyi.fly.controller;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.PageDomain;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.fly.domain.PcUser;
import com.ruoyi.fly.domain.vo.DeleteVo;
import com.ruoyi.fly.domain.vo.PcUserSearchVo;
import com.ruoyi.fly.domain.vo.UserUpdateVo;
import com.ruoyi.fly.service.PcUserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/pcUser")
@Api(tags = "app用户管理")
public class PcUserController extends BaseController {

    @Autowired
    private PcUserService userService;


    /**
     * 查询用户列表
     */
    @ApiOperation(value = "查询用户列表")
    @PostMapping("/list")
    public TableDataInfo list(@RequestBody PcUserSearchVo pcUserSearchVo) {
        PageDomain pageDomain = new PageDomain();
        BeanUtils.copyProperties(pcUserSearchVo,pageDomain);
        startPage(pageDomain);
        List<PcUser> list = userService.selectCAuthUserList(pcUserSearchVo);
        return getDataTable(list);
    }

    /**
     * 根据id获取用户详细信息
     */
    @ApiOperation(value = "根据id获取用户详细信息")
    @GetMapping(value = "/selUser/{id}")
    public R<PcUser> getInfo(@PathVariable("id") String id) {
        return R.ok(userService.selectCAuthUserById(id));
    }

//    /**
//     * 新增用户
//     */
//    @PostMapping
//    public R add(@RequestBody UserUpdateVo userUpdateVo) {
//        return R.ok(userService.insertCAuthUser(userUpdateVo));
//    }

    /**
     * 修改用户
     */
    //@ApiOperation(value = "修改用户")
    @PostMapping("/editUser")
    public R edit(@RequestBody UserUpdateVo userUpdateVo) {
        return userService.updateCAuthUser(userUpdateVo);
    }

    /**
     * 删除用户
     */
    //@ApiOperation(value = "删除用户")
    @PostMapping("/deleteUser")
    public R remove(@RequestBody DeleteVo deleteVo) {
        return userService.deleteCAuthUserByIds(deleteVo.getIds());
    }
}
